<template>
	<el-dialog :title="dialogTitle" :visible.sync="visible" top="0" width="560px" append-to-body>
		<el-form v-bind="formConfig" :model="formData" :rules="formRules" label-width="80px" v-loading="loading">
			<el-row :gutter="16">
				<el-col :span="24">
					<el-form-item label="分类类型" prop="classType">
						<el-radio-group size="small" v-model="formData.classType" v-removeAriaHidden>
							<template v-for="(item, index) in dictEnums['SYS_CLASSIFY']">
								<el-radio :label="item.deValue">{{ item.deName }}</el-radio>
							</template>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="分类名称" prop="name">
						<el-input v-model="formData.name" placeholder="请输入分类名称"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="分类状态" prop="status">
						<el-radio-group v-model="formData.status" v-removeAriaHidden>
							<el-radio label="1">正常</el-radio>
							<el-radio label="2">禁用</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="排序" prop="orderBy">
						<el-input-number v-model="formData.orderBy" controls-position="right" :min="1" style="width: 100%" />
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="分类描述">
						<el-input type="textarea" v-model="formData.des"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template slot="footer">
			<el-button size="medium" @click="visible = false">取消</el-button>
			<el-button size="medium" type="primary" :loading="loading" @click="handleSubmitForm()">{{ formTypeText }}</el-button>
		</template>
	</el-dialog>
</template>

<script>
import { mapGetters } from 'vuex';
import formMixins from '@/mixins/formMixins';
import { classifyDetail, addClassify, updateClassify } from '@/api/course/sysClassify';
export default {
	mixins: [formMixins],
	props: {
		type: { type: String, default: '' }
	},
	data() {
		return {
			formName: '分类',
			formRules: {
				classType: [{ required: true, message: '请选择分类类型', trigger: 'change' }],
				name: [{ required: true, message: '请输入分类名称', trigger: 'blur' }]
			}
		};
	},
	computed: {
		...mapGetters(['dictEnums']),
		detailData() {
			return eval(classifyDetail);
		},
		callFunction() {
			return eval(this.addOrEdit ? addClassify : updateClassify);
		}
	},
	methods: {
		formatFormParams() {
			this.$set(this.formData, 'classType', this.type);
		}
	}
};
</script>
